#include <gtest/gtest.h>

#include <thread>
#include <vector>

#include "JSIExecutorTest.h"

#if 0
TEST_P(JSIExecutorTest, TestJsThread) {
  jsiexecutor::JSIExecutor quickjsExecutor(std::move(runtime), nullptr);

  std::thread thread1(jsiCreateObject, &quickjsExecutor);
  logInfo("jsiCreateObject run ok1\n" );
  thread1.join();
  logInfo("jsiCreateObject run ok2\n");

  //  quickjsExecutor.createObject(reinterpret_cast<const uint8_t*>(json.c_str()), json.length());

  std::string script = R"(
    (function(){
      globalThis = new Function("return this")();
      function $print(msg){
          console.log(msg);
      }
      globalThis.$print=$print;
      var $data = globalThis.$data;
      console.log($data);
      var $expression = [
          ()=> console.log($data.x),
          ()=> $data.y,
          ()=> console.log("abc")
      ];
      globalThis.$expression = $expression;
    })();
    globalThis.$print("hello");
    )";

  quickjsExecutor.loadBundle(std::make_unique<facebook::jsi::StringBuffer>(script), "test");
  auto res = quickjsExecutor.callFunction("$print", 1234);
  auto exp = quickjsExecutor.callFunction(0);
}

TEST_P(JSIExecutorTest, TestBytecodeThread) {
  const uint8_t qjsc_hello[59] = {
      0x02, 0x03, 0x0a, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x0a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x10,
      0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x6a, 0x73, 0x0e, 0x00, 0x06, 0x00, 0xa2, 0x01, 0x00,
      0x01, 0x00, 0x02, 0x00, 0x00, 0x0d, 0x01, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x38, 0xe3, 0x00,
      0x00, 0x00, 0x04, 0xe4, 0x00, 0x00, 0x00, 0xf1, 0xcf, 0x28, 0xca, 0x03, 0x01, 0x00,
  };
  std::string script(reinterpret_cast<const char*>(qjsc_hello), 59);
  jsiexecutor::JSIExecutor quickjsExecutor(std::move(runtime), nullptr);
  quickjsExecutor.loadBundle(std::make_unique<facebook::jsi::StringBuffer>(script), "test");
}
#endif